// pages/search/search.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    assets: app.config.assets,
    keyword:"",
    hot_keywords:[{keyword:'java'},{keyword:'大数据'}],
    courses:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu({
      complete: (res) => {},
    })
    this.getData();
  },
  getData: function(){
    var context = this;
    wx.request({
      url: app.config.server + "/api/hot_keywords",
      success: res => {
        context.setData({
          hot_keywords:res.data
        })
      }
    })
  },

  inputKeyword: function(e){
    this.setData({
      keyword:e.detail.value
    })
  },
  tapSearch: function(e){
    this.setData({
      keyword:e.currentTarget.dataset.keyword
    });
    var context = this;
    wx.request({
      url: app.config.server + "/api/search?keyword="+this.data.keyword,
      header:{
        sessionkey: wx.getStorageSync('session_key')
      },
      success: res => {
        context.setData({
          courses:res.data
        })
      }
    })
  },
  navigate: function(e){    
    wx.navigateTo({
      url: e.currentTarget.dataset.url,
    })
  }
})